import { Entity, OneToOne, JoinColumn, PrimaryColumn, } from 'typeorm';
import { Student } from './student.entity';
import { Wristband } from './wristband.entity';

@Entity('student_wristband')
export class StudentWristband {
  @PrimaryColumn({ name: 'mac', type: 'char', length: 17})
  mac: string;

  @PrimaryColumn({ name: 'sid', type: 'int' })
  sid: number;


  // @OneToOne(() => Student, student => student.id)
  // @JoinColumn({ name: 'sid' })
  // student: Student;

  // @OneToOne(() => Wristband, wristband => wristband.mac)
  // @JoinColumn({ name: 'mac' })
  // wristband: Wristband;

  // 一对一关系：一个关联记录对应一个学生
  @OneToOne(() => Student)
  @JoinColumn({ name: 'sid', referencedColumnName: 'id' })
  student: Student;

  // 一对一关系：一个关联记录对应一个手环
  @OneToOne(() => Wristband)
  @JoinColumn({ name: 'mac', referencedColumnName: 'mac' })
  wristband: Wristband;
}
